package com.songminju.jsong_httpserver.server.bio;

import java.net.ServerSocket;
import java.net.Socket;

import com.songminju.jsong_httpserver.HttpServerConfig;
import com.songminju.jsong_httpserver.server.AbstractHttpServer;

public class BIOHttpServer extends AbstractHttpServer{

	private ServerSocket serverSocket;
	
	public BIOHttpServer(HttpServerConfig config) {
		super(config);
	}

	@Override
	public void startSync() throws Exception {
		serverSocket = new ServerSocket(config.getPort());
		RequestAdapter adapter = new RequestAdapter(config.getHander());
		Thread adapterThread = new Thread(adapter);
		adapterThread.start();
		while(true) {
			Socket socket = serverSocket.accept();
			RequestConnection rc = new RequestConnection(socket);
			adapter.put(rc);
		}
		
	}
}
